package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.Login;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 礼包兑换
 * 
 * @author mujianchen
 * 
 */

public class UIGiftBag implements IUIWindows
{

	private DWFrame m_gbFrame = null;
	private DWTitle m_gbTitle = null;

	private DWImageBox m_gbImageBox_GB = null;//关闭按钮
	private Bitmap m_gbBitmap_GB = null;//关闭图片

	private DWBackground m_gbBackground = null;//背景

	private Bitmap m_gbBitmap01 = null;//按钮
	private Bitmap m_gbBitmap02 = null;//按钮下

	private DWImageBox m_gbImageBox_BT = null;//标题图标
	private Bitmap m_gbBitmap_BT = null;

	private DWTextbox m_gbTextbox01 = null;//内测礼包领取
	private DWTextbox m_gbTextbox02 = null;//内测工会礼包领取
	private DWTextbox m_gbTextbox03 = null;//输入兑换码领取

	private DWInputBox m_gbInputBox = null;//输入框

	private DWButton m_gbButton01 = null;//内测礼包领取 确定按钮
	private DWButton m_gbButton02 = null;//内测工会礼包领取 确定按钮
	private DWButton m_gbButton03 = null;//输入兑换码领取 确定按钮

	public static String NC_LB = "libao_neice";//内测礼包领取
	public static String NC_GH_LB = "libao_gonghui";//内测工会礼包领取
	public static String DHM_LB = "qita";//输入兑换码领取

	public void init()
	{
		m_gbBitmap_GB = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");//关闭按钮

		m_gbBitmap_BT = UIWindows.createImage("/img/newui/duihuanlibao.gnp");//标题

		m_gbBitmap01 = UIWindows.createImage("/img/newui/anniu_1.gnp");//按钮
		m_gbBitmap02 = UIWindows.createImage("/img/newui/anniu_1ax.gnp");//按钮下
	}

	public void giftBag()
	{
		m_gbFrame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_gbTitle = new DWTitle(null, m_gbFrame);

		m_gbImageBox_BT = new DWImageBox(m_gbBitmap_BT);
		m_gbImageBox_BT.setNearAnchor(m_gbTitle, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_gbBackground = new DWBackground(m_gbFrame.getShowWidth(), m_gbFrame.getShowHeight() - 10);
		m_gbBackground.setNearAnchor(m_gbFrame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM);

		m_gbImageBox_GB = new DWImageBox(m_gbBitmap_GB);
		m_gbImageBox_GB.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close((byte) 0);
			}
		});
		m_gbImageBox_GB.setNearAnchor(m_gbTitle, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_gbImageBox_GB.setTouchZoomIn(20, 20);

		m_gbTextbox01 = new DWTextbox("内测礼包领取：");
		m_gbTextbox02 = new DWTextbox("内测公会礼包领取：");
		m_gbTextbox03 = new DWTextbox("输入兑换码领取：");

		m_gbTextbox01.setNearAnchor(m_gbFrame, Tools.LEFT_TOP, Tools.LEFT_TOP, 50, 50);
		m_gbTextbox02.setNearAnchor(m_gbTextbox01, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 50);
		m_gbTextbox03.setNearAnchor(m_gbFrame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, -50);

		m_gbInputBox = new DWInputBox(250, 40, m_gbFrame);
		m_gbInputBox.setNearAnchor(m_gbFrame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 20);
		m_gbInputBox.setText(null);

		m_gbButton01 = new DWButton("领取", m_gbBitmap01);
		m_gbButton02 = new DWButton("领取", m_gbBitmap01);
		m_gbButton03 = new DWButton("确定", m_gbBitmap01);

		m_gbButton01.setDownImage(m_gbBitmap02);
		m_gbButton02.setDownImage(m_gbBitmap02);
		m_gbButton03.setDownImage(m_gbBitmap02);

		m_gbButton01.setNearAnchor(m_gbTextbox01, Tools.LEFT_TOP, Tools.LEFT_TOP, 200, 0);
		m_gbButton02.setNearAnchor(m_gbTextbox02, Tools.LEFT_TOP, Tools.LEFT_TOP, 200, 0);
		m_gbButton03.setNearAnchor(m_gbFrame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -20, -20);

		m_gbButton01.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				Login.Read();
				DWGameManager.getInstance().getSendMessage().sendGiftBagExchange(Login.m_back_l_ib1, NC_LB);
			}
		});

		m_gbButton02.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				Login.Read();
				DWGameManager.getInstance().getSendMessage().sendGiftBagExchange(Login.m_back_l_ib1, NC_GH_LB);
			}
		});

		m_gbButton03.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (m_gbInputBox.getText() != null) {
					DWGameManager.getInstance().getSendMessage().sendGiftBagExchange(m_gbInputBox.getText(), DHM_LB);
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "请输入兑换码");
				}
			}
		});

		m_gbFrame.addControl(m_gbBackground);
		m_gbFrame.addControl(m_gbTitle);
		m_gbFrame.addControl(m_gbImageBox_BT);
		m_gbFrame.addControl(m_gbImageBox_GB);
//		m_gbFrame.addControl(m_gbTextbox01);
//		m_gbFrame.addControl(m_gbTextbox02);
		m_gbFrame.addControl(m_gbTextbox03);
		m_gbFrame.addControl(m_gbInputBox);
//		m_gbFrame.addControl(m_gbButton01);
//		m_gbFrame.addControl(m_gbButton02);
		m_gbFrame.addControl(m_gbButton03);
		DWControlsManager.getInstance().addControl(m_gbFrame);
	}

	public void open(byte index)
	{
		try {
			giftBag();
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void close(byte index)
	{
		m_gbInputBox.setText(null);
		DWControlsManager.getInstance().removeControl(m_gbFrame);
	}

	public void dispose()
	{

	}

	public void logic()
	{

	}

}
